-- SpecialSkillInfoM
-- created by zouyb
-- 专属技能信息表

module("SpecialSkillInfoM", package.seeall);

local infos = {};
local propInfos = {};

-- 载入配置表
local _init = false;
local loadCsv = function()
    if _init then return end
    _init = true;

    -- 转换下special_skill_info信息表
    local special_skill_info_CSV = get_special_skill_info_CSV();
    local id, propId;
    for i = 1, #special_skill_info_CSV do
        id = special_skill_info_CSV[i].id;
        infos[id] = special_skill_info_CSV[i];

        -- 按prop_id初始化
        propId = special_skill_info_CSV[i].prop_id;
        propInfos[propId] = propInfos[propId] or {};
        propInfos[propId][id] = special_skill_info_CSV[i];
    end

    special_skill_info_CSV = {};
end

-- 模块初始化操作
function init()
    loadCsv();
end

-- 检索
function query(cmd, path)
    local m = infos[cmd];

    if not m or not path then
        return m;
    end

    return m[path];
end

-- 查询prop对应的技能信息
function queryProp(propId)
    return propInfos[propId];
end

-- 获取要触发专属技特效的宠物
function getSpecialTriggerPets(propId, propKey)
    -- propId、key相对应，并且是出战或链接的宠物
    local petList = PetM.getDungeonPetList();
    local info = queryProp(propId) or {};
    local ret = {};

    for _, petId in pairs(petList) do
        repeat
            -- 没有对应的prop_id
            if not info[petId] then
                break;
            end

            -- 检查key是否相对应
            -- 如果key没有配置或者没有传入，跳过这步检查（默认对应）
            local key = query(petId, "key");
            if key and key ~= "" and propKey then
                if key ~= propKey then
                    break;
                end
            end

            table.insert(ret, petId);
        until true;
    end

    return ret;
end